<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>企业信息修改</title>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css"> 
<style type="text/css">
	#changeCompInfoDiv{
		width:800px;
		margin:0 auto;
	}
	.divx1{
		width:800px;
		margin-top:20px;
		padding-top:30px;
	}
	.divx2{
		width:150px;
		height:35px;
		float:left;
		font-size:16px;
		font-family:"黑体";
	}
	.divx3{
		width:350px;
		float:left;
	}
	.divx4{
		margin-left:20px;
		width:200px;
		height:35px;
		float:left;
		font-size:12px;
		font-family:"宋体";
	}
	#allDiv{
		margin-top:60px;
	}
</style>
</head>
	<body>
		<div id="allDiv">
			<div id="changeCompInfoDiv">
				<form onsubmit="return check()" action="updateCompanyInfo.do" method="post">
				
				<div class="divx1">  
					<div class="divx2">
						<label>企业登录名：</label>
					</div>
					<div class="divx3">
						<input id="compName" class="form-control" name="companyName" type="text" onblur="checkCompName();" />
					</div>  
					<div class="divx4">
						<label id="label1" class="help-block">待验证</label>
					</div>
				</div>
				
				<div class="divx1">  
					<div class="divx2">
						<label>企业登录密码：</label>
					</div>
					<div class="divx3">
						<input id="password" class="form-control"  name="password" name="" class="input-xlarge" type="password" onblur="checkPassword();"  placeholder="请输入新密码"/>
					</div>  
					<div class="divx4">
						<label id="passwordMessage">支持字母和数字</label>
					</div>
				</div>
				<div class="divx1">  
					<div class="divx2">
						<label>确认密码：</label>
					</div>
					<div class="divx3">
						<input id="newPassword" class="form-control"  onblur="checkNewPassword()"  type="password" />
					</div>  
					<div class="divx4">
						<label id="newPasswordMessage" class="help-block">和上一步输入一致</label>
					</div>
				</div>
				<div class="divx1">  
					<div class="divx2">
						<label>企业名称：</label>
					</div>
					<div class="divx3">
						<label id="companyName" class="form-control"  ></label>
					</div>  
					<div class="divx4">
						<label class="help-block">此项不可修改</label>
					</div>
				</div>
				<div class="divx1">  
					<div class="divx2">
						<label>企业楼层位置：</label>
					</div>
					<div class="divx3">
						<label id="companyFolder" class="form-control" ></label>
					</div>  
					<div class="divx4">
						<label class="help-block">此项不可修改</label>
					</div>
				</div>
				<div class="divx1">  
					<div class="divx2">
						<label>企业联系人：</label>
					</div>
					<div class="divx3">
						<input id="companyBoss" name="companyBoss" class="form-control"  type="text" onblur="checkCompanyBoss()"  />
					</div>  
					<div class="divx4">
						<label id="companyBossMessage" class="help-block">请输入中文</label>
					</div>
				</div>
				<div class="divx1">  
					<div class="divx2">
						<label>企业联系电话：</label>
					</div>
					<div class="divx3">
						<input id="companyTel" name="companyTel" class="form-control"  type="text"  onblur="checkTel()" />
					</div>  
					<div class="divx4">
						<label id="companyTelMessage" class="help-block">请输入有效联系方式</label>
					</div>
				</div>
				<div class="divx1" >
					<div style="margin-left:350px;">
						<input type="submit" onclick="return check()" id="bt1" class="btn btn-success" value="提交" />
						<input type="hidden" name="id" id="companyID" value="${sessionScope.myCompany.companyID }" >
					</div>
				</div>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../js/jquery-3.1.0.min.js"></script>
	<script type="text/javascript">
		$(function(){
			getCompInfo($("#companyID").val());
		})
		function getCompInfo(companyID){
			$.ajax({
				   type: "get",
				   url: "../../findCompanyById.do",
				   data: "companyID="+companyID,
				   success: function(msg){
				   	 document.getElementById("companyFolder").innerHTML=msg.companyAddress;
				   	 document.getElementById("companyName").innerHTML=msg.companyName;
				   }
			});
		}
		function check() {
			var flag = checkCompName() && checkPassword() && checkNewPassword() && checkCompanyBoss() &&checkTel();
			return flag;
		}
		function checkCompName(){
			var inputName=document.getElementById("compName").value;
			if(inputName==""){
				document.getElementById("label1").innerHTML="请输入用户名";
				return false;
			}else{
				document.getElementById("label1").innerHTML="";
				$.ajax({
					   type: "POST",
					   url: "../../findUserByName.do",
					   data: "inputName="+inputName,
					   success: function(msg){
					     if(msg!=null&&msg!=""){
					    	 document.getElementById("label1").innerHTML="已被占用，请重输";
					    	 return false;
					     }else{
					    	 document.getElementById("label1").innerHTML="该名字可用";
					    	 return true;
					     }
					   }
				});
			}
		}
		function checkPassword(){
			var password = document.getElementById("password").value;
			var passwordMessage = document.getElementById("passwordMessage");
			var eReg =  /^[a-zA-Z][a-zA-Z0-9]{5,19}$/;
			if (password.length == 0) {
				passwordMessage.innerHTML = "密码不能为空";
				return false;
			} else if (!eReg.test(password)) {
				passwordMessage.innerHTML = "密码必须以字母开头，且长度为6-20位";
				return false;
			} else {
				passwordMessage.innerHTML = "写对啦！";
				return true;
			}		
		}
		function checkNewPassword(){
			var password = document.getElementById("password").value;
			var newPassword = document.getElementById("newPassword").value;
			var passwordMessage = document.getElementById("newPasswordMessage");
			newPasswordMessage
			if(password==newPassword){
				passwordMessage.innerHTML = "nice boy!";
				return true;
			}else {
				passwordMessage.innerHTML = "瓜娃子记性那么挫！";
				return false;
			}	
		}
		function checkCompanyBoss(){
			var companyBoss = document.getElementById("companyBoss").value;
			var companyBossMessage = document.getElementById("companyBossMessage");
			var eReg =   /^[\u4e00-\u9fa5]{3,15}$/;
			if (companyBoss.length == 0) {
				companyBossMessage.innerHTML = "联系人不能为空";
				return false;
			} else if (!eReg.test(companyBoss)) {
				companyBossMessage.innerHTML = "必须为3-15位的中文汉字";
				return false;
			} else {
				companyBossMessage.innerHTML = "写对啦！";
				return true;
			}
		}
		function checkTel() {
			var companyTel = document.getElementById("companyTel").value;
			var companyTelMessage = document.getElementById("companyTelMessage");
			var eReg = /^1[34578]\d{9}$/;
			if (companyTel.length == 0) {
				companyTelMessage.innerHTML = "电话号码不能为空";
				return false;
			} else if (!eReg.test(companyTel)) {
				companyTelMessage.innerHTML = "电话号码格式不正确";
				return false;
			} else {
				companyTelMessage.innerHTML = "写对啦！";
				return true;
			}
		}
	</script>
</html>